import axios from 'axios'
import qsString from 'querystring'
axios.interceptors.request.use(req=>req)
axios.interceptors.response.use(res=>res)
export const get = (url,params={})=>{
    return new Promise((resolve,reject)=>{
        axios.get(url,{
            params
        })
        .then(res=>resolve(res))
        .catch(err=>reject(err))
    })
}
export const post = (url,params={},isFile=false)=>{
    let data = {}
    if(isFile){
        //有上传文件
        data = new FormData()
        for(let i in params){
            data.append(i,params[i])
        }
    }else{
        data = qsString.stringify(params)
    }
    return new Promise((resolve,reject)=>{
        axios.post(url,data)
        .then(res=>resolve(res))
        .catch(err=>reject(err))
    })
}